<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>nodeName,nodeValue</title>
  </head>
  
  <body>
	  <!--nodeName,nodeValue-->
	  <div id="container">这是一个元素节点</div>
    
	<script>
      var documentCount = 0;
      /**
      * 使用log方法打印出此页面包含的所有节点的 nodeName 和 nodeType (换行符除外)
      **/
	  
      var divElement = document.getElementById("container");
	  var documentNode = window.document;
	  var doctype =document.doctype||document.childNodes[0]|| document.firstChild ;
	  var docAttr = document.documentElement.attributes[0];
	  
	  var head = document.head || document.getElementsByTagName("head")[0];
	  var meta = head.firstElementChild || document.getElementsByTagName("meta")[0];
	  var metaAttr = meta.attributes[0];
	  var title = head.firstElementChild.nextElementSibling || document.getElementsByTagName("title")[0];
	  var titleText = head.firstElementChild.nextElementSibling.firstChild || document.getElementsByTagName("title")[0].firstChild;
	  var body = divElement.parentNode ||  document.body || document.getElementsByTagName("body")[0] ;
	  var comment = divElement.previousSibling.previousSibling;
	  var divElementAttr = divElement.attributes[0];
	  var divElementText = divElement.firstChild;
	  var script = document.getElementsByTagName("script")[0];
	  var scriptText = document.getElementsByTagName("script")[0].firstChild;
	  
	  log("文档节点  " , documentNode )
	  log("<!DOCTYPE html> ", doctype );
	  log("html ", document.documentElement);
	  log("lang='en'", docAttr);
	  log("head ", head );
	  log("meta ", meta);
	  log("charset='UTF-8'", metaAttr);
	  log("title ", title);
	  log("标题文字 ", titleText );
	  log("body ", body );
	  log("<!--nodeName,nodeValue--> ", comment );
      log("div ",  divElement);
	  log("id='container' ",  divElementAttr);
	  log("这是一个元素节点 ", divElementText );
	  log("script ", script);
	  log("script内容 ", scriptText);
      console.log("共有node节点："+documentCount+"个");


      function log(explanation,node){
        var strArr = [];
        strArr.push("节点位置: [ "+explanation+" ]");
        strArr.push("节点名字: "+node.nodeName);
        strArr.push("节点类型: "+node.nodeType);
        documentCount++;
        console.log(strArr.join("  "));
      }
      
    </script> 
  </body>
</html>